package org.lisen.quartzjdbc.controller;

import org.lisen.quartzjdbc.scheduler.PrintService;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author laughing
 * @date 2020/9/29
 * @site https://www.lisen.org
 */
@RestController
public class QuartzController {

    @RequestMapping("/quartzJdbc")
    public String quartzJdbc() throws SchedulerException {

        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger","triGroup")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(1)
                        .withRepeatCount(0))
                .build();

        JobDetail job = JobBuilder.newJob(PrintService.class)
                .usingJobData("JobKey","JobValue")
                .withIdentity("Job","JobGroup")
                .withDescription("打印任务")
                .build();
        scheduler.scheduleJob(job, trigger);
        scheduler.pauseAll();
        return "success";
    }

}
